package com.ssy.wireless.web.service;

import com.ssy.wireless.entity.Account;
import com.ssy.wireless.mapper.AccountMapper;
import com.ssy.wireless.util.MD5;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.util.Assert;

/**
 * Created by cofey on 16/11/18.
 */
@Service
@Transactional(readOnly = true)
public class AccountService {
    @Autowired
    private AccountMapper accountMapper;

    public Account login(String loginUser, String password) {
        Account account = accountMapper.login(loginUser);
        Assert.notNull(account, "账号不存在");
        Assert.isTrue(account.getPassword().equals(MD5.getInstance().exec(password)), "账号密码错误");
        return account;
    }

    @Transactional
    public int updateUserPwd(Account account) {
        return accountMapper.updateByPrimaryKey(account);
    }
}
